var RunLayer = cc.Layer.extend({
	arr:null,
	scene:null,
	clock:null,
	ctor:function (parent) {
		this._super();
		this.scene = parent;
		this.scene.addChild(this, 10);
		gg.main = this;
		this.init();
	},
	init:function () {
		this.callNext = cc.callFunc(function(){
			gg.flow.next();
		}, this);
		this.callNext.retain();
		this.clock = new Clock(this);
		// 物品库
		this.lib = new Lib(this);
		this.instrument=new Instrument(this,"#lite.png",TAG_MP_INSTRUMENT);
		this.scheduleOnce(function(){
// this.loadTest();
		},1);
	},
	loadTest:function(){
 this.lib.moveLib(TAG_LIB_SALT,400);
// ll.run.loadBeaker(cc.p(900,900));
// ss = ll.run.getChildByTag(TAG_BEAKER4);
	},
	show:function(){
		var electrode_show=new Button(this,15,TAG_ELECTRODE_SHOW,"#electrode_show.png",this.callback,this);
		electrode_show.setPosition(cc.p(gg.width*0.5,gg.height*0.6));
		electrode_show.setOpacity(0);
		var fadein=cc.fadeIn(1);
		var fadeout=cc.fadeOut(1);
		electrode_show.runAction(cc.sequence(fadein,cc.delayTime(1),fadeout));
	},
	test2:function(){
		var move = cc.moveTo(0.7,cc.p(570,320));
		var rotate = cc.rotateTo(0.8, 90);
		var func = cc.callFunc(function(){
			ss.pour2();
			ss.hide(3, true);
		},this);
		var seq = cc.sequence(move, rotate, func);
		ss.runAction(seq);
	},
	loadInstrument:function(pos){
		var instrument=new Button(this,10,TAG_INSTRUMENT,"#Instrument.png",this.callback,this);
		this.loadInLib(instrument, pos,cc.p(gg.width*0.3, gg.height*0.4));
	},
	loadElectrode:function(pos){
		var electrode=new Electrode(this);
		this.addChild(electrode,10);
		this.loadInLib(electrode, pos,cc.p(gg.width*0.5,gg.height*0.4));
	},
	loadBottle:function(pos){
		var bottle=new Bottle(this);
		this.addChild(bottle,20);
		this.loadInLib(bottle, pos,cc.p(gg.width*0.8, gg.height*0.4));
	},
	loadBattery:function(pos){
		this.instrument.embedded();
	},
	loadFilm:function(pos){
		var film=new Button(this,10,TAG_FILM,"#film.png",this.callback,this);
		this.loadInLib(film, pos,cc.p(gg.width*0.828,gg.height*0.4));
	},
	loadKettle:function(pos){
		var kettle=new Button(this,10,TAG_KETTLE,"#kettle.png",this.callback,this);
		this.loadInLib(kettle, pos,cc.p(gg.width*0.8,gg.height*0.4));
		var title=new Button(kettle,10,TAG_KETTLE,"#label1.png",this.callback,this);
		title.setPosition(kettle.width*0.5, kettle.height*0.35);
	},
	loadBeaker:function(pos){
		var beaker=new Beaker(this, 10, TAG_BEAKER, this.callback);
		this.loadInLib(beaker, pos,cc.p(gg.width*0.75,gg.height*0.4));
	},
	loadBottle1:function(pos){
		var bottle1=new Bottle1(this);
		this.addChild(bottle1,10);
		this.loadInLib(bottle1, pos,cc.p(gg.width*0.9,gg.height*0.4));
	},
	loadInLib:function(obj, pos, tarPos,delay){
		obj.setPosition(pos);
		if(delay == null){
			delay = 1;
		}
		var ber = $.bezier(pos, tarPos, delay);
		var seq = cc.sequence(ber, this.callNext);
		obj.runAction(seq);
	},
	kill:function(obj){
		var fade = cc.fadeTo(0.5,0);
		var func = cc.callfunc(function(){
			obj.removeFromParent(true);
		},this);
		var seq = cc.sequence(fade,func);
		obj.runAction(seq)
	},
	callback:function (p){
		var func = cc.callFunc(this.actionDone, this);
		var func1=cc.callFunc(function(){
			gg.flow.next();
		}, this);
		var instrument=this.getChildByTag(TAG_MP_INSTRUMENT);
		switch(p.getTag()){
		case TAG_INSTRUMENT:
			gg.flow.next();
			instrument.show();
			break;
		case TAG_KETTLE:
			var electrode=ll.run.getChildByTag(TAG_ELECTRODE_ALL);
			var right1=electrode.getChildByTag(TAG_RIGHT1);
			var right2=right1.getChildByTag(TAG_RIGHT2);
			var right3=right1.getChildByTag(TAG_RIGHT3);
			var left_1=electrode.getChildByTag(TAG_LEFT_1);
			var left_2=left_1.getChildByTag(TAG_LEFT_2);
			var left_3=left_1.getChildByTag(TAG_LEFT_3);
			var body=electrode.getChildByTag(TAG_ELECTRODE);
			var ber=cc.bezierBy(1, [cc.p(-30,50),cc.p(-80,80),cc.p(-330,135)]);
			var rotate=cc.rotateBy(1,-65);
			p.runAction(cc.sequence(cc.callFunc(function() {
				right1.setVisible(true);
				p.setVisible(false);
				left_1.setVisible(true);
				body.setVisible(false);
			},this),cc.callFunc(function() {
				right1.runAction(cc.sequence(ber,rotate,cc.delayTime(1),rotate.reverse(),cc.callFunc(function() {
					right1.setVisible(false);
					this.show();
				},this)));
			},this),cc.delayTime(7),func1));
			break;
		default:
			break;
		}
	},
	actionDone:function(p){
		var func = cc.callFunc(this.actionDone, this);
		switch(p.getTag()){
			
		}
	}
});